package com.recallgo.manage.web.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.recallgo.manage.entity.User;
import com.recallgo.manage.entity.vo.PageVO;
import com.recallgo.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author fendo
 * @since 2018-09-11
 */
@RestController
@RequestMapping("/rest/user")
public class UserController {

    @Autowired
    private UserService userService;
    /**
     * 分页查询会员信息
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseEntity<PageVO<User>> queryUserList(@RequestParam("page") Integer page, @RequestParam("rows") Integer rows){
        Page<User> userPage = new Page<>(page, rows);
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.orderBy("updated DESC");
        Page<User> tbUserPage = userService.selectPage(userPage, wrapper);

        PageVO<User> pageVO = new PageVO<>();
        pageVO.setTotal((int) tbUserPage.getTotal());
        pageVO.setRows(tbUserPage.getRecords());
        return ResponseEntity.ok(pageVO);
    }
}

